import crypto from "crypto-js";
import coookie from "js-cookie";

const key = crypto.enc.Utf8.parse("PAW_KEY_XU123456");
const iv = crypto.enc.Utf8.parse("PAW_KEY_XU123456");

export const enCrypto = (obj: any) => {
  const srcs = crypto.enc.Utf8.parse(obj);
  const cipher = crypto.AES.encrypt(srcs, key, {
    iv: iv,
    mode: crypto.mode.ECB,
    padding: crypto.pad.Pkcs7,
  });
  return cipher.toString();
};

export const deCrypto = (obj: any) => {
  const decrypt = crypto.AES.decrypt(obj, key, {
    iv: iv,
    mode: crypto.mode.ECB,
    padding: crypto.pad.Pkcs7,
  });
  return crypto.enc.Utf8.stringify(decrypt).toString();
};

export const setCookie = (name, value, opts?) => {
  coookie.set(name, value, opts);
};

export const getCookie = (name) => {
  return coookie.get(name);
};

export const removeCookie = (name) => {
  return coookie.remove(name);
};
